package org.cainiao.basic.reflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class LoggingHandler implements InvocationHandler {
    private final Object target;

    public LoggingHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("Calling method: " + method.getName());
        System.out.println("With arguments: " + args[0] + ", " + args[1]);

        Object result = method.invoke(target, args);

        System.out.println("Result: " + result);
        return result;
    }
}
